<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>查看库存货品</title>
    <link type="text/css" rel="stylesheet" href="./layui/css/layui.css"/>
    <style rel="stylesheet" type="text/css">
        .right{
            margin-right: 5px;
            text-align: center;
        }
    </style>
</head>
<div class="evaluateProfit" style="display: none;">
    <div class="layui-form-item">
        <label class="layui-form-label">售完预计利润</label>
        <div class="layui-input-block">
            <input readonly="true" type="text" name="profit" required lay-verify="required"  autocomplete="off"
                   class="layui-input profit" style="width: 200px">
            <label class="layui-form-label"></label>
        </div>
    </div>
</div>
<body class="layui-layout-body">
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>库存货品</legend>
</fieldset>





<table id="product" lay-filter="article-filter"></table>
<script type="text/html" id="toolBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="evaluateProfit">预计利润</a>
    <a class="layui-btn layui-btn-xs" lay-event="onsale">上架货品</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="return">货品退货</a>
</script>
<script src="./layui/layui.all.js"></script>
<script>
    var $ = layui.jquery;
    var table = layui.table;
    var element = layui.element;
    table.render({
        elem: '#product'
        , height: 500
        , url: '/selectrepositoryproduct.action' //数据接口
        , cols: [[ //表头
            {field: 'pid', title: 'ID', width: 80, sort: false, fixed: 'left'}
            , {field: 'pname', title: '货品名称', width: 190}
            , {field: 'pgetprice', title: '货品进价', width: 150, sort: false}
            , {field: 'psaleprice', title: '货品售价', width: 200, sort: false}
            , {field: 'pduetime', title: '过期时间', width: 240, sort: false}
            , {field: 'pcount', title: '货品余量', width: 120, sort: false}
            , {width: 300, title: '常用操作', align: 'center', toolbar: '#toolBar', fixed: 'right'}

        ]]
        ,page : true
    });
</script>
<script>
    //监听工具条
    table.on('tool(article-filter)', function (obj) {
        if (obj.event === 'evaluateProfit') {
            console.log("sdasd")
            var data = obj.data;
            layer.open({
                type: 1,
                skin: 'layui-layer-demo', //样式类名
                closeBtn: 1, //不显示关闭按钮
                anim: 2,
                shadeClose: true, //开启遮罩关闭
                area: ['400px', '140px'],
                content: $('.evaluateProfit')
            });
            var evaProfit = (parseInt(data.psaleprice) - parseInt(data.pgetprice)) * parseInt(data.pcount);
            $(".profit").val(evaProfit);


        }
//        else if (obj.event === 'onsale') {
//            var data = obj.data;
//            layer.confirm('确定上架该商品吗?', function (index) {
//                $.ajax({
//                    url: "/reptoonsale.action?id=" + data.id,
//                    type: "POST",
//                    data: data
//                });
//                obj.del();
//                layer.close(index);
//            });
//        } else if (obj.event === 'return') {
//            var data = obj.data;
//            layer.confirm('真的退货该商品吗?', function (index) {
//                $.ajax({
//                    "url": "/productreturn.action?pid=" + data.pid,
//                });
//                obj.del();
//                layer.close(index);
//            });
//        }
    });
</script>
</body>
</html>